home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -in_the_mag- / program_perfection / vbcc / mystartup / minstart.s < prev    next >
Text File  |  2000-03-11  |  4KB  |  146 lines

  1. *
  2. *   Minstart.s
  3. *
  4. *   Fairly minimal startup code for VBCC
  5. *   See mystart.doc for details
  6. *
  7. *   (C) Richard Drummond 1999
  8. *
  9. *   Please feel free to use and abuse this code in your own
  10. *   programs, but don't blame me if it goes wrong . . .
  11. *
  12. *   $Id :$
  13. *   $Log: minstart.s,v $
  14. *   Revision 1.2  2000/02/14 00:18:25  EvilRich
  15. *   Fixed Enforcer hit
  16. *
  17. *   Revision 1.1.1.1  1999/11/10 22:38:28  richard
  18. *   Initial import to cvs
  19. *
  20. *
  21.  
  22.  
  23.     section "CODE",code
  24.  
  25.  
  26.  
  27.     xref    __main
  28.     xref    _LVOOpenLibrary
  29.     xref    _LVOCloseLibrary
  30.     xref    _LVOWaitPort
  31.     xref    _LVOGetMsg
  32.     xref    _LVOForbid
  33.     xref    _LVOReplyMsg
  34.     xref    _LVOOpenLibrary
  35.     xref    _LVOCloseLibrary
  36.     xref    _LVOAlert
  37.  
  38.     xdef    __exit
  39.     xdef    _SysBase
  40.     xdef    _DOSBase
  41.     xdef    _WBenchMsg
  42.  
  43.     near    a4,-2
  44.     initnear
  45.  
  46.     move.l  4.w,_SysBase(a4)    ;   Set up SysBase
  47.     move.l  a7,InitialSP(a4)    ;   Remember stack pointer
  48.  
  49. ;    This caused an Enforcer hit when started from WB - oops!
  50. ;    We now check for WB startup first
  51. ;    clr.b   -1(a0,d0)           ;   Make sure argument string ends in NULL
  52. ;    subq.l  #1, d0              ;   D0 is now the length of arg string
  53.  
  54. ;    move.l  d0, -(a7)           ;   Shove pointer & length of arg string
  55. ;    move.l  a0, -(a7)           ;   on stack for passing to main()
  56.  
  57.     move.l  d0, d7              ;   Temporarily store pointer and length
  58.     move.l  a0, a3              ;   of arg string
  59.  
  60.     move.l  _SysBase(a4), a6
  61.     move.l  $114(A6),A0         ;   Get pointer to our task from ExecBase
  62.  
  63.     cmp.b   #13,8(A0)           ;   Is it a process
  64.     bne     skip                ;   Nope
  65.  
  66.     tst.l   $AC(A0)             ;   Is it a CLI ?
  67.     bne     skip                ;   Nope
  68.  
  69.     lea     $5C(A0),A0          ;   Find our message port
  70.  
  71.     move.l  a0, a3
  72.     jsr     _LVOWaitPort(A6)    ;   Wait for WB message at port
  73.  
  74.     move.l  a3,a0
  75.     jsr     _LVOGetMsg(A6)      ;   Get it
  76.  
  77.     move.l  d0,_WBenchMsg(a4)   ;   Store it
  78.     sub.l   d0, d0
  79.     move.l  d0, a0              ;   Clear a0/d0
  80.     bra     skip4
  81.  
  82. skip
  83.     move.l  a3, a0              ;   Restore ptr and len to a0/d0
  84.     move.l  d7, d0
  85.  
  86.     clr.b   -1(a0,d0)           ;   Make sure argument string ends in NULL
  87.     subq.l  #1, d0              ;   D0 is now the length of arg string
  88.  
  89. skip4
  90.     move.l  d0, -(a7)           ;   Shove pointer & length of arg string
  91.     move.l  a0, -(a7)           ;   on stack for passing to main()
  92.  
  93.     lea     dosname(pc),a1
  94.     moveq.l #0, d0
  95.     jsr     _LVOOpenLibrary(a6) ;   open dos.library
  96.     move.l  d0, _DOSBase(a4)    ;   store base address
  97.     bne     ok
  98.  
  99.     move.l  #$38007,D7          ;   failed to open DOS
  100.     jsr     _LVOAlert(a6)       ;   so do Alert()
  101.  
  102.     move.l  #20, d2             ;   Fatal Error
  103.     bra     skip2
  104.  
  105. ok
  106.     jsr     __main              ;   Call _main()
  107.  
  108. __exit
  109.     move.l  d0, d2              ;   Hold onto return code
  110.  
  111.     move.l  _SysBase(a4), a6
  112.     move.l  _DOSBase(a4), a1
  113.     jsr     _LVOCloseLibrary(a6)    ; Close dos.library
  114.  
  115. skip2
  116.     move.l  _WBenchMsg(a4),d3       ;   Do we need to reply to WBMsg?
  117.     beq     skip3               ;   Nope
  118.  
  119.     jsr     _LVOForbid(a6)      ;   Yes
  120.     move.l  d3,a1
  121.     jsr     _LVOReplyMsg(a6)    ;   Reply
  122.  
  123. skip3
  124.     move.l  d2 ,d0              ;   Restore return code
  125.     move.l  InitialSP(a4), a7;  ;   Restore stack pointer
  126.     rts
  127.  
  128. dosname
  129.     dc.b    'dos.library',0
  130.  
  131.  
  132.     section "__MERGED",data
  133.  
  134. InitialSP
  135.     dc.l    0
  136.  
  137. _SysBase
  138.     dc.l    0
  139.  
  140. _DOSBase
  141.     dc.l    0
  142.  
  143. _WBenchMsg
  144.     dc.l    0
  145.  
  146.